//
//  CNKIPublishView.m
//  CNKICommunity
//
//  Created by wei on 17/2/9.
//  Copyright © 2017年 CNKI. All rights reserved.
//

#import "CNKIPublishView.h"
#import <POP.h>
#import "CNKIPublishBtn.h"
@interface CNKIPublishView()



@end


@implementation CNKIPublishView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self setUp];
    }
    return self;
}
-(void)setUp
{
    NSArray *ButtonImage = @[@"publish-video",@"publish-picture",@"publish-text",@"publish-audio",@"publish-review",@"publish-offline"];
    NSArray *ButtonTitle = @[@"发视频",@"发图片",@"发段子",@"发声音",@"审帖",@"更多"];
    
    int masCol = 3;
    int Xmargin = 20;
    for (int i = 0; i < ButtonImage.count; i++)
    {
        CNKIPublishBtn *button = [[CNKIPublishBtn alloc]init];
        [button setImage:[UIImage imageNamed:ButtonImage[i]] forState:UIControlStateNormal];
        [button setTitle:ButtonTitle[i] forState:UIControlStateNormal];
        button.titleLabel.textColor = [UIColor blackColor];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        [button addTarget:self action:@selector(PublishButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = i + 101;
        
        
        CGFloat row = i / masCol;//行数 用于计算y
        CGFloat col = i % masCol;//列数 用于计算x
    
        CGFloat buttonW = (SCREENWIDTH - Xmargin * (masCol + 1)) / 3;
        CGFloat buttonH = buttonW + 30;
        CGFloat buttonBeginX = (col + 1) * Xmargin + col * buttonW;
        CGFloat buttonBeginy = SCREENHEIGHT + row * buttonH;
        CGFloat buttonEndy = SCREENHEIGHT / 2 + row * buttonH;
        
        POPSpringAnimation *animation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
        animation.fromValue = [NSValue valueWithCGRect:CGRectMake(buttonBeginX, buttonBeginy, buttonW, buttonH)];
        animation.toValue = [NSValue valueWithCGRect:CGRectMake(buttonBeginX, buttonEndy, buttonW, buttonH)];
        animation.springBounciness = 10;
        animation.springSpeed = 10;
        animation.beginTime = CACurrentMediaTime() + 0.1 * i;
        [button pop_addAnimation:animation forKey:nil];
        
        [self addSubview:button];
        
    }
    
    UIButton *tabbarbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    tabbarbtn.frame = CGRectMake(0, SCREENHEIGHT - 50, SCREENWIDTH, 50);
    [tabbarbtn setTitle:@"关闭" forState:UIControlStateNormal];
    tabbarbtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [tabbarbtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [tabbarbtn setBackgroundColor:[UIColor grayColor]];
    tabbarbtn.tag = 211;
    [tabbarbtn addTarget:self action:@selector(PublishButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:tabbarbtn];
    
}
-(void)PublishButtonClick:(UIButton*)sender
{
    if ([_ButtonClickDelegate respondsToSelector:@selector(ClickButtontag:)])
    {
        [_ButtonClickDelegate ClickButtontag:sender.tag - 101];
    }
}
@end
